<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="utf-8"/>
    <title>下单</title>
    <link th:href="@{/project/css/public.css}" rel="stylesheet"/>
    <link th:href="@{/project/css/proList.css}" rel="stylesheet"/>
    <link th:href="@{/project/css/mygxin.css}" rel="stylesheet"/>
</head>
<body>
<!----------------------------------------head------------------>
<div class="head ding" th:include="include::normal_headDiv2"></div>
<form id="submitOrder" th:action="@{/AlipayController/PayPage}" method="post">
    <input type="hidden" name="isFromCart" th:value="${isFromCart}">
    <input type="text" name="receiveAddr" id="receiveAddr" value="">
    <input type="text" name="receiveUser" id="receiveUser" value="">
    <input type="text" name="receiveTel" id="receiveTel" value="">
    <input type="text" name="totalPrice" id="totalPrice" value="">
    <div class="order cart mt">
        <!-----------------orderCon------------------->
        <div class="orderCon wrapper clearfix">
            <div class="orderL fl" style="width: 100%;">
                <!--------h3---------------->
                <h3>送货地址<a href="javascript:openAddrAdd()" class="fr">新增地址</a></h3>
                <!--------addres---------------->
                <div class="addres clearfix">
                    <div th:each="addr,indexObj:${addrList}"
                         th:attr="class=${indexObj.index ==0?'addre fl on':'addre fl'},data-addr=${addr.province+addr.city+addr.district+addr.receiveAddr},data-user=${addr.receiveUser},data-tel=${addr.receiveTel}">
                        <div class="tit clearfix">
                            <p class="fl">
                                <span th:text="${addr.receiveUser}"></span>
                                <span th:if="${indexObj.index ==0}" class="default">[默认地址]</span>
                            </p>
                            <p class="fr">
                                <a href="javascript:void(0)" th:onclick="|editAddr(${addr.id})|" class="edit">编辑</a>
                            </p>
                        </div>
                        <div class="addCon">
                            <p th:text="${addr.province+addr.city+addr.district+addr.receiveAddr}">/p>
                            <p th:text="${addr.receiveTel}"></p>
                        </div>
                    </div>
                </div>

            </div>
            <div class="orderR fl" style="width: 100%;margin-bottom: 30px;">
                <div class="msg">
                    <h3>订单内容</h3>
                    <!--------ul---------------->
                    <ul class="clearfix" th:each="userCart,iterStat:${dataList}">
                        <li class="fl col01">
                            <input type="hidden" name="goodsId" th:value="${userCart.goodsInfo.goodsId}">
                            <input type="hidden" name="goodsName" th:value="${userCart.goodsInfo.goodsName}">
                            <input type="hidden" name="goodsNum" th:value="${userCart.goodsNum}">
                            <input type="hidden" name="goodsPrice" th:value="${userCart.goodsInfo.goodsPrice}">
                            <img th:src="${userCart.goodsInfo.imgUrl}">
                        </li>
                        <li class="fl col02">
                            <p class="leave_out" th:text="${userCart.goodsInfo.goodsName}"></p>
                            <span class="leave_out" th:text="${userCart.goodsInfo.attr1}"></span>
                        </li>
                        <li class="fl col03">
                            <span>单价：￥</span><span th:text="${userCart.goodsInfo.goodsPrice}"></span>
                        </li>
                        <li class="fl col04">
                            <span>数量：</span><span th:text="${userCart.goodsNum}"></span>
                        </li>
                        <li class="fl col05">
                            <span>小计：￥</span><span></span>
                        </li>
                    </ul>
                </div>
                <!--------tips---------------->
                <div class="tips">
                    <p><span class="fr" id="total1">￥139.80</span><span class="fr">餐饮金额：</span></p>
                    <p><span class="fr" id="minusMoney">￥0.00</span><span class="fr">会员优惠金额：</span></p>
                </div>
                <!--------tips count---------------->
                <div class="count tips">
                    <p><span class="fr"></span><span class="fr">合计：</span></p>
                </div>
                <div class="count tips">
                    <p><textarea name="remark" class="fr" style="width: 100%;height: 60px;"
                                 placeholder="备注:"></textarea></p>
                </div>
                <div class="orderL fl" style="width: 100%;">
                    <h3>支付方式</h3>
                    <!--------way---------------->
                    <div style="margin-top: 20px"><img th:src="@{/img/alipay.jpg}" style="width: 120px;height: 42px"></div>
                </div>
                <a href="javascript:$('#submitOrder').submit()" class="pay fr">下单</a>
            </div>
        </div>
    </div>
</form>
<div id="footer" th:include="include::normal_footerDiv"></div>
<div th:include="include::footer_normal"></div>
<script th:src="@{/project/cart.js}"></script>
<script th:inline="javascript">
    // $.form.init({
    //     "formId": "submitOrder",
    //     "url": ctx + "Alipay/PayPage",
    //     "beforeSubmit": function () {
    //         if ($("#receiveAddr").val() == "" || $("#receiveTel").val() == "" || $("#receiveUser").val() == "") {
    //             showAlert("请添加收货地址！");
    //             return false;
    //         }
    //         return true;
    //     },
    //     "success": function (data) {
    //         if (data.code == web_status.NOT_LOGIN) {
    //             location.href = ctx + "login";
    //             return;
    //         }
    //         if (data.code == web_status.SUCCESS) {
    //             showAlert("下单成功！", 2000, function () {
    //                 location.href = ctx + "user/order";
    //             });
    //         } else {
    //             $.modal.msgError(data.msg);
    //         }
    //     }
    // });
    $(function () {
        var totalPrice = 0;
        var isvip = [[${isvip}]];
        $(".orderR ul").each(function () {
            var price = $(this).find(".col03 span:eq(1)").html();
            var num = $(this).find(".col04 span:eq(1)").html();
            var itemTotal = $.count.multiply(price, num).toFixed(2);
            $(this).find(".col05 span:eq(1)").html(itemTotal);
            totalPrice = $.count.add(totalPrice, itemTotal);
        });
        $("#total1").html('￥' + totalPrice.toFixed(2));
        if (isvip == 'Y') {
            $("#minusMoney").html('￥' + (totalPrice * 0.1).toFixed(2));
            totalPrice = totalPrice * 0.9;
        }
        $(".orderR .count span:eq(0)").html(totalPrice.toFixed(2) + "元");
        $("#totalPrice").val(totalPrice.toFixed(2));

        $(".addre").click(function () {
            $(this).addClass("on").siblings().removeClass("on");
            var data = $(this).data();
            $("#receiveAddr").val(data.addr);
            $("#receiveUser").val(data.user);
            $("#receiveTel").val(data.tel);
        });
        $(".addre:eq(0)").click();
        $(".dis span").click(function () {
            $(this).addClass("on").siblings().removeClass("on");
        });
    });
</script>
</body>
</html>
